package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    @Select("select * from shopping_cart where user_id = #{id}")
    List<ShoppingCart> getById(Long id);

    List<ShoppingCart> list(ShoppingCart shoppingCart);

    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 根据用户id清空购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (user_id, name, image, dish_id,dish_flavor,setmeal_id, amount, number, create_time) " +
            "values (#{userId}, #{name}, #{image}, #{dishId},#{dishFlavor},#{setmealId}, #{amount}, #{number}, #{createTime})")
    void insert(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> showShoppingCarts(ShoppingCart shoppingCart);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void cleanShoppingCart(Long userId);

    @Delete("delete from shopping_cart where id = #{id}")
    void deleteByUserId(Long userId);
}
